//
//  IDCTutorialViewController.m
//  GamePlan
//
//  Created by iD Student on 7/16/13.
//  Copyright (c) 2013 jasonkurtzman. All rights reserved.
//

#import "IDCTutorialViewController.h"
#import "IDCAllOthersViewController.h"
#import "IDCContentModel.h"
#import "IDCAppDelegate.h"


@interface IDCTutorialViewController ()
@end

@implementation IDCTutorialViewController{
    
    NSArray *arrayControlers;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //self.delegate = self;
    self.dataSource = self;
    
    IDCAllOthersViewController *vc = [((IDCAppDelegate *)[UIApplication sharedApplication].delegate).contentModel getVCforModule:self.model page:0];
    
    [self setViewControllers: [NSArray arrayWithObjects:
                        vc,nil] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
    
	// Do any additional setup after loading the view.
}


//- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers
//{
//
//}
//
//// Sent when a gesture-initiated transition ends. The 'finished' parameter indicates whether the animation finished, while the 'completed' parameter indicates whether the transition completed or bailed out (if the user let go early).
//- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed{
//    
//    
//    
//}
//// Delegate may specify a different spine location for after the interface orientation change. Only sent for transition style 'UIPageViewControllerTransitionStylePageCurl'.
//// Delegate may set new view controllers or update double-sided state within this method's implementation as well.
//- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation{
//    if(UIInterfaceOrientationIsPortrait(orientation))
//    {
//        //Set the array with only 1 view controller
//        UIViewController *currentViewController = [arrayControlers objectAtIndex:0];
//        NSArray *viewControllers = [NSArray arrayWithObject:currentViewController];
//        [self setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];
//        
//        //Important- Set the doubleSided property to NO.
//        self.doubleSided = NO;
//        //Return the spine location
//        return UIPageViewControllerSpineLocationMin;
//        
//    }else{
//        
//    }
//}
//
//
//// In terms of navigation direction. For example, for 'UIPageViewControllerNavigationOrientationHorizontal', view controllers coming 'before' would be to the left of the argument view controller, those coming 'after' would be to the right.
//// Return 'nil' to indicate that no more progress can be made in the given direction.
//// For gesture-initiated transitions, the page view controller obtains view controllers via these methods, so use of setViewControllers:direction:animated:completion: is not required.

//-(IDCAllOthersViewController *) viewControllerAtIndex:(NSUInteger)index
//{
//    
//    
//    self.storyboard instantiateViewControllerWithIdentifier:
//    IDCAllOthersViewController *childViewController = [[IDCAllOthersViewController alloc] initWithNibName:@"IDCAllOthersViewController" bundle:nil];
//    childViewController.index = index;
//    
//    return childViewController;
//}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(IDCAllOthersViewController *)viewController{
    if(viewController.index == 0)
        return nil;
    
    NSLog(@"Index Before: %d", viewController.index-1);
    IDCAllOthersViewController *vc = [((IDCAppDelegate *)[UIApplication sharedApplication].delegate).contentModel getVCforModule:self.model page:viewController.index-1];
    return vc;
    
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(IDCAllOthersViewController *)viewController{

    int count = [((IDCAppDelegate *)[UIApplication sharedApplication].delegate).contentModel getPageCountForModule:self.model];
    NSLog(@"Count: %d", count);
    
    
    if(viewController.index >= count-1)
        return nil;

    viewController.index += 1;
    IDCAllOthersViewController *vc = [((IDCAppDelegate *)[UIApplication sharedApplication].delegate).contentModel getVCforModule:self.model page:viewController.index];
    return vc;
}


// A page indicator will be visible if both methods are implemented, transition style is 'UIPageViewControllerTransitionStyleScroll', and navigation orientation is 'UIPageViewControllerNavigationOrientationHorizontal'.
// Both methods are called in response to a 'setViewControllers:...' call, but the presentation index is updated automatically in the case of gesture-driven navigation.
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
    
    return [arrayControlers count];
    
    
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
    return 0;
}
// The selected item reflected in the page indicator.





- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
